const { insertData, findData, findOneData, updateData, requstPromise } = require('../utils')
const { updateUserInfo } = require('./user')
const crypto = require('crypto')

const Integral = {
    // 给用户增加积分
    async addIntegral(option) {
        const { openId, integral } = option
        return requstPromise(await updateUserInfo('camluniUser', {
            openId, // 用户id
            integral, // 积分
        }))
    },
    
    // 查找全国排行榜
    async findAllList(option) {
        return requstPromise(await findData('camluniUser', {}, { 'integral': -1 }, 0, 10))
    },
    
    // 查找好友排行榜
    async findList(option) {
        return requstPromise(await findOneData('camluniUser', { inviter: option.openId }, { 'integral': -1 }, 0, 10))
    },
}

module.exports = Integral
